function getData(endpoint, cb) {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', endpoint);

  xhr.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200) {
      const data = JSON.parse(this.responseText);
      cb(data);
    }
  }

  setTimeout(() => {
    xhr.send();
  }, Math.floor(Math.random() * 3000) + 1000)
}

// getData("./movies.json")
// getData("./actors.json")
// getData("./directors.json")

getData("./movies.json", (movies) => {
  console.log(movies);
  getData("./actors.json", (actors) => {
    console.log(actors);
    getData("./directors.json", (directors) => {
      console.log(directors);
    })
  })
})

